import os
import cv2

img_root = '../OTB100_RES/uav0000138_00000_v'
fps = 15

dest_vids = '../OTB100_RES_vid/uav0000138_00000_v.avi'
file_names = os.listdir(img_root)
file_names.sort()
ex_img = cv2.imread(os.path.join(img_root, file_names[0]))
size=(ex_img.shape[1], ex_img.shape[0])
#可以用(*'DVIX')或(*'X264'),如果都不行先装ffmepg: sudo apt-get install ffmepg
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video_writer = cv2.VideoWriter(dest_vids, fourcc, fps, size)

#for(i=1;i<471;++i)
for file_name in file_names:
    frame = cv2.imread(os.path.join(img_root, file_name))
    frame = cv2.resize(frame, (size[0], size[1]))
    video_writer.write(frame)
    cv2.imshow('ori', frame)
    # cv2.imshow('dd', img)
    cv2.waitKey(1)
video_writer.release()


